package com.fare.taluo.core.domain.entity.crawl;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.OneToMany;

import org.apache.commons.lang.math.RandomUtils;
import org.apache.commons.lang3.StringUtils;

import com.fare.taluo.base.ddd.domain.BaseHBaseEntity;
import com.fare.taluo.base.ddd.domain.annontation.HBaseColumn;


/**
 * 详细历史数据模型(Hbase)
 * @author Administrator
*/
@javax.persistence.Table(name = "CRAWL_DETAIL_INFO")
public class StaticHistoryHbaseEntity extends BaseHBaseEntity{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * 创建时间
	 */
	@HBaseColumn(qualifier = "createTime", family = "crawlInfos", format = "yyyyMMddHHmmssSSS")
	protected Date createTime = new Date();
	
	/**
	 * 抓取日期
	*/
	@HBaseColumn(qualifier = "grabDate", family = "crawlInfos")
	protected String grabDate ;
	
	/**
	 * 任务ID
	*/
	@HBaseColumn(qualifier = "taskId", family = "crawlInfos")
	protected String taskId;
	
	/**
	 * 起飞日期
	*/
	@HBaseColumn(qualifier = "flightDate", family = "crawlInfos")
	protected String flightDate;
	
	/**
	 * 返程日期
	*/
	@HBaseColumn(qualifier = "returnFlightDate", family = "crawlInfos")
	protected String returnFlightDate;
	
	/**
	 * 任务优先级
	*/
	@HBaseColumn(qualifier = "priority", family = "crawlInfos")
	protected int priority;
	
	/**
	 * 抓取状态
	*/
	@HBaseColumn(qualifier = "status", family = "crawlInfos")
	protected int status;
	
	/**
	 * 开始时间
	*/
	@HBaseColumn(qualifier = "startTime", family = "crawlInfos" , format="yyyy-MM-dd HH:mm:ss")
	protected Date startTime;
	
	/**
	 * 结束时间
	*/
	@HBaseColumn(qualifier = "endTime", family = "crawlInfos" , format="yyyy-MM-dd HH:mm:ss")
	protected Date endTime;
	
	/**
	 * 抓取渠道ID
	 * */
	@HBaseColumn(qualifier = "grabChannelId", family = "crawlInfos")
	protected Long grabChannelId;
	
	/**
	 * 抓取渠道名称
	 */
	@HBaseColumn(qualifier = "grabChannel", family = "crawlInfos")
	protected String grabChannelName;
	
	/**
	 * 源文件Rowkey
	*/
	@HBaseColumn(qualifier = "rowKey", family = "crawlInfos")
	protected String rowKey;
	
	/**
	 * fromCityName
	*/
	@HBaseColumn(qualifier = "fromCityName", family = "crawlInfos")
	protected String fromCityName;
	
	@HBaseColumn(qualifier = "fromCity", family = "crawlInfos")
	protected String fromCity;
	
	/**
	 * toCityName
	*/
	@HBaseColumn(qualifier = "toCityName", family = "crawlInfos")
	protected String toCityName;
	
	@HBaseColumn(qualifier = "toCity", family = "crawlInfos")
	protected String toCity;
	
	/**
	 * 任务投放次数
	*/
	@HBaseColumn(qualifier = "excuteCount", family = "crawlInfos")
	protected int excuteCount;
	
	/**
	 * 任务抓取数量
	*/
	@HBaseColumn(qualifier = "crawlCount", family = "crawlInfos")
	protected int crawlCount;
	
	@OneToMany
	@HBaseColumn(qualifier = "details", family = "details")
	private Set<DetailInfoEntity> details=new HashSet<DetailInfoEntity>();
	
	
	public Set<DetailInfoEntity> getDetails() {
		return details;
	}

	public void setDetails(Set<DetailInfoEntity> details) {
		this.details = details;
	}

	public String getTaskId() {
		return taskId;
	}

	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}
	
	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Long getGrabChannelId() {
		return grabChannelId;
	}

	public void setGrabChannelId(Long grabChannelId) {
		this.grabChannelId = grabChannelId;
	}

	public String getGrabChannelName() {
		return grabChannelName;
	}

	public void setGrabChannelName(String grabChannelName) {
		this.grabChannelName = grabChannelName;
	}

	public String getRowKey() {
		return rowKey;
	}

	public void setRowKey(String rowKey) {
		this.rowKey = rowKey;
	}

	public String getFromCityName() {
		return fromCityName;
	}

	public void setFromCityName(String fromCityName) {
		this.fromCityName = fromCityName;
	}

	public String getToCityName() {
		return toCityName;
	}

	public void setToCityName(String toCityName) {
		this.toCityName = toCityName;
	}

	public String getFlightDate() {
		return flightDate;
	}

	public void setFlightDate(String flightDate) {
		this.flightDate = flightDate;
	}

	public String getReturnFlightDate() {
		return returnFlightDate;
	}

	public void setReturnFlightDate(String returnFlightDate) {
		this.returnFlightDate = returnFlightDate;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public String getFromCity() {
		return fromCity;
	}

	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}

	public String getToCity() {
		return toCity;
	}

	public void setToCity(String toCity) {
		this.toCity = toCity;
	}

	public int getExcuteCount() {
		return excuteCount;
	}

	public void setExcuteCount(int excuteCount) {
		this.excuteCount = excuteCount;
	}

	public int getCrawlCount() {
		return crawlCount;
	}

	public void setCrawlCount(int crawlCount) {
		this.crawlCount = crawlCount;
	}

	public String getGrabDate() {
		return grabDate;
	}

	public void setGrabDate(String grabDate) {
		this.grabDate = grabDate;
	}

	/**
	 * 存入hbase表的rowkey
	 * 航空数据（00001）+渠道id三位数据（001）+抓取日期（yyyyMMdd）+任务状态3位数(1开头表示正状态，0开对表示负状态)+随机数据5位
	*/
	@Override
	public String generateRowKey() {
		return new StringBuilder()
		.append("00001")
		.append(this.getGrabChannelId()>=100?this.getGrabChannelId()+"":(this.getGrabChannelId()>=10?"0"+this.getGrabChannelId():"00"+this.getGrabChannelId()))
		.append(this.grabDate.replaceAll("-", ""))
		.append(this.status<0?(Math.abs(this.status)<10?"00"+Math.abs(this.status):"0"+Math.abs(this.status)):(this.status<10?"10"+this.status:"1"+this.status))
		.append(StringUtils.leftPad(String.valueOf(RandomUtils.nextInt(99999)), 5, '0'))
		.toString();
	}

}
